<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/7/12
 * Time: 10:47
 */
//------------------------
//考勤
//-------------------------
namespace app\attendance\controller;

use app\attendance\Base;
use com\gdl\kq\dataobject\adminuser\UserDTO;
use com\gdl\kq\dataobject\approvalprocess\approvalProcessDTO;
use com\gdl\kq\dataobject\attendancegroup\AttendanceGroupDTO;
use com\gdl\kq\dataobject\setholidays\setholidaysDTO;
use com\gdl\kq\interfaces\ApprovalProcessServiceClient;
use com\gdl\kq\interfaces\AttAdminAttendanceGroupServiceClient;
use com\gdl\kq\interfaces\AttAdminUserServiceClient;
use com\gdl\kq\interfaces\SetholidaysServiceClient;
use think\Config;
use think\Db;
use think\Exception;
use think\Loader;
class Attendance extends Base
{
    //添加考勤组
    public function addAttendanceGroup()
    {
        $title = $this->request->param('title') ? $this->request->param('title') : 0;
        //考勤组名称
        $platformId = $this->request->param('platformId') ? $this->request->param('platformId') : 0;
        //平台ID
        $setholidaysId = $this->request->param('setholidaysId') ? $this->request->param('setholidaysId') : 0;
        //节假日设置ID
        $goDaysNum = $this->request->param('goDaysdata') ? json_decode(htmlspecialchars_decode($this->request->param('goDaysdata'))) : [];
        //一天内上下班的次数
        $unusualStatus = $this->request->param('unusualStatus') ? json_decode(htmlspecialchars_decode($this->request->param('unusualStatus'))) : [];
        //异常定义
        $coordinate = $this->request->param('coordinate') ? json_decode(htmlspecialchars_decode($this->request->param('coordinate'))) : [];
        //签到点坐标
        $coordinateName = $this->request->param('coordinateName') ? json_decode(htmlspecialchars_decode($this->request->param('coordinateName'))) : [];
        //签到地点名
        $coordinateTitle = $this->request->param('coordinateTitle') ? json_decode(htmlspecialchars_decode($this->request->param('coordinateTitle'))) : [];
        //签到地点名
        $coordinateDeviation = $this->request->param('coordinateDeviation') ? json_decode(htmlspecialchars_decode($this->request->param('coordinateDeviation'))) : [];
        //签到范围
        $groupMustUser = $this->request->param('groupMustUser') ? json_decode(htmlspecialchars_decode($this->request->param('groupMustUser'))) : [];
        //参与考勤人员
        $groupNotUser = $this->request->param('groupNotUser') ? json_decode(htmlspecialchars_decode($this->request->param('groupNotUser'))) : [];
        //无需考勤人员
        $approvalProcessOne = $this->request->param('approvalProcessOne') ? $this->request->param('approvalProcessOne') : 0;
        //请假审批流程方案ID
        $approvalProcessTwo = $this->request->param('approvalProcessTwo') ? $this->request->param('approvalProcessTwo') : 0;
        //外出审批流程方案ID
        $approvalProcessThree = $this->request->param('approvalProcessThree') ? $this->request->param('approvalProcessThree') : 0;
        //补卡审批流程方案ID
        $offDutyOut = $this->request->param('offDutyOut') ? $this->request->param('offDutyOut') : 1;
        // 下班是否需要打卡 1打卡 2不打卡
        $faceStatus = $this->request->param('faceStatus') ? $this->request->param('faceStatus') : 1;
        // 是否开启人脸 1开启 2不开启
        $trackLocation = $this->request->param('trackLocation') ? $this->request->param('trackLocation') : 1;
        // 1不开启轨迹定位 2开启轨迹定位
        $adminUserId = $this->request->param('adminUserId') ? $this->request->param('adminUserId') : 0;
        $type = $this->request->param('type') ? $this->request->param('type') : 1;
        //1正常考勤组 2公共考勤组
        $adminReg = $this->request->param('adminReg') ? getStr($this->request->param('adminReg')) : '';
        $unitId = $this->request->param('unitId') ? getStr($this->request->param('unitId')) : '';
        if (empty($title)) {
            $data = ['msg' => '请填写考勤组名称', 'code' => 400, 'data' => []];
            return json_encode($data);
        } elseif (empty($setholidaysId)) {
            $data = ['msg' => '请选择节假日设置', 'code' => 400, 'data' => []];
            return json_encode($data);
        } elseif (empty($goDaysNum)) {
            $data = ['msg' => '请选择上班时间段', 'code' => 400, 'data' => []];
            return json_encode($data);
        } elseif (empty($coordinate)) {
            $data = ['msg' => '请选择考勤地点', 'code' => 400, 'data' => []];
            return json_encode($data);
        } elseif (empty($approvalProcessOne)) {
            $data = ['msg' => '请选择请假流程', 'code' => 400, 'data' => []];
            return json_encode($data);
        }
        try {
            \ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlCloudSdk'));
            $api = new AttAdminAttendanceGroupServiceClient(NULL);
            \ApiClient::build($api);
            $data = [
                'title' => $title,
                'setholidaysId' => $setholidaysId,
                'platformId' => $platformId,
                'goDaysNum' => json_encode($goDaysNum),
                'unusualStatus' => json_encode($unusualStatus),
                'coordinate' => json_encode($coordinate),
                'coordinateName' => json_encode($coordinateName),
                'coordinateTitle' => json_encode($coordinateTitle),
                'coordinateDeviation' => json_encode($coordinateDeviation),
                'groupMustUser' => json_encode($groupMustUser),
                //['units'=>[1,2,3],'userid'=>[3,5,6]]
                'groupNotUser' => json_encode($groupNotUser),
                //['units'=>[1,2,3],'userid'=>[3,5,6]]
                'approvalProcessOne' => $approvalProcessOne,
                'approvalProcessTwo' => $approvalProcessTwo,
                'approvalProcessThree' => $approvalProcessThree,
                'offDutyOut' => $offDutyOut,
                'faceStatus' => $faceStatus,
                'trackLocation' => $trackLocation,
                'adminUserId' => $adminUserId,
                'adminReg' => $adminReg,
                'type' => $type,
                'unitId' => $unitId,
            ];
            $AttendanceGroupDTO = new AttendanceGroupDTO();
            $AttendanceGroupDTO->data = $data;
            //            $engprojectDo->userid	= $adminUserId;
            //            $engprojectDo->adminReg		= $adminReg;
            $result = $api->addAttendanceGroup($AttendanceGroupDTO);
            $pdata = [];
            if ($result->code) {
                /*****测试原型*****/
                $pdata = $result->data;
            }
            //checkstate 1是选中 0是未选中
            $data = ['msg' => '添加成功', 'code' => 200, 'data' => $pdata];
        } catch (Exception $ex) {
            $data = ['msg' => '获取失败', 'code' => 400, 'data' => []];
        }
        return json_encode($data);
    }
    //修改考勤组
    public function editAttendanceGroup()
    {
        $Id = $this->request->param('Id') ? $this->request->param('Id') : 0;
        //考勤组Id
        $title = $this->request->param('title') ? $this->request->param('title') : 0;
        //考勤组名称
        $platformId = $this->request->param('platformId') ? $this->request->param('platformId') : 0;
        //平台ID
        $setholidaysId = $this->request->param('setholidaysId') ? $this->request->param('setholidaysId') : 0;
        //节假日设置ID
        $goDaysNum = $this->request->param('goDaysdata') ? json_decode(htmlspecialchars_decode($this->request->param('goDaysdata'))) : [];
        //一天内上下班的次数
        $unusualStatus = $this->request->param('unusualStatus') ? json_decode(htmlspecialchars_decode($this->request->param('unusualStatus'))) : [];
        //异常定义
        $coordinate = $this->request->param('coordinate') ? json_decode(htmlspecialchars_decode($this->request->param('coordinate'))) : [];
        //签到点坐标
        $coordinateName = $this->request->param('coordinateName') ? json_decode(htmlspecialchars_decode($this->request->param('coordinateName'))) : [];
        //签到地点名
        $coordinateTitle = $this->request->param('coordinateTitle') ? json_decode(htmlspecialchars_decode($this->request->param('coordinateTitle'))) : [];
        //签到地点名
        $coordinateDeviation = $this->request->param('coordinateDeviation') ? json_decode(htmlspecialchars_decode($this->request->param('coordinateDeviation'))) : [];
        //签到范围
        $groupMustUser = $this->request->param('groupMustUser') ? json_decode(htmlspecialchars_decode($this->request->param('groupMustUser'))) : [];
        //参与考勤人员
        $groupNotUser = $this->request->param('groupNotUser') ? json_decode(htmlspecialchars_decode($this->request->param('groupNotUser'))) : [];
        //无需考勤人员
        $approvalProcessOne = $this->request->param('approvalProcessOne') ? $this->request->param('approvalProcessOne') : 0;
        //请假审批流程方案ID
        $approvalProcessTwo = $this->request->param('approvalProcessTwo') ? $this->request->param('approvalProcessTwo') : 0;
        //外出审批流程方案ID
        $approvalProcessThree = $this->request->param('approvalProcessThree') ? $this->request->param('approvalProcessThree') : 0;
        //补卡审批流程方案ID
        $offDutyOut = $this->request->param('offDutyOut') ? $this->request->param('offDutyOut') : 1;
        // 下班是否需要打卡 1打卡 2不打卡
        $faceStatus = $this->request->param('faceStatus') ? $this->request->param('faceStatus') : 1;
        // 是否开启人脸 1开启 2不开启
        $trackLocation = $this->request->param('trackLocation') ? $this->request->param('trackLocation') : 1;
        // 1不开启轨迹定位 2开启轨迹定位
        $adminUserId = $this->request->param('adminUserId') ? $this->request->param('adminUserId') : 0;
        $type = $this->request->param('type') ? $this->request->param('type') : 1;
        //1正常考勤组 2公共考勤组
        $adminReg = $this->request->param('adminReg') ? getStr($this->request->param('adminReg')) : '';
        $unitId = $this->request->param('unitId') ? getStr($this->request->param('unitId')) : '';
        //        if (empty($title) || empty($setholidaysId)|| empty($platformId) || empty($goDaysNum) || empty($groupMustUser)|| empty($groupNotUser)){
        //            $data = ['msg'=>'参数错误','code'=>400,'data'=>[]];
        //            return json_encode($data);
        //        }
        if (empty($title)) {
            $data = ['msg' => '请填写考勤组名称', 'code' => 400, 'data' => []];
            return json_encode($data);
        } elseif (empty($setholidaysId)) {
            $data = ['msg' => '请选择节假日设置', 'code' => 400, 'data' => []];
            return json_encode($data);
        } elseif (empty($goDaysNum)) {
            $data = ['msg' => '请选择上班时间段', 'code' => 400, 'data' => []];
            return json_encode($data);
        } elseif (empty($coordinate)) {
            $data = ['msg' => '请选择考勤地点', 'code' => 400, 'data' => []];
            return json_encode($data);
        } elseif (empty($approvalProcessOne)) {
            $data = ['msg' => '请选择请假流程', 'code' => 400, 'data' => []];
            return json_encode($data);
        }
        if (empty($Id)) {
            $data = ['msg' => '参数错误', 'code' => 400, 'data' => []];
            return json_encode($data);
        }
        try {
            \ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlCloudSdk'));
            $api = new AttAdminAttendanceGroupServiceClient(NULL);
            \ApiClient::build($api);
            $data = [
                'title' => $title,
                'setholidaysId' => $setholidaysId,
                'platformId' => $platformId,
                'goDaysNum' => json_encode($goDaysNum),
                'unusualStatus' => json_encode($unusualStatus),
                'coordinate' => json_encode($coordinate),
                'coordinateName' => json_encode($coordinateName),
                'coordinateTitle' => json_encode($coordinateTitle),
                'coordinateDeviation' => json_encode($coordinateDeviation),
                'groupMustUser' => json_encode($groupMustUser),
                //['units'=>[1,2,3],'userid'=>[3,5,6]]
                'groupNotUser' => json_encode($groupNotUser),
                //['units'=>[1,2,3],'userid'=>[3,5,6]]
                'approvalProcessOne' => $approvalProcessOne,
                'approvalProcessTwo' => $approvalProcessTwo,
                'approvalProcessThree' => $approvalProcessThree,
                'offDutyOut' => $offDutyOut,
                'faceStatus' => $faceStatus,
                'trackLocation' => $trackLocation,
                'adminUserId' => $adminUserId,
                'adminReg' => $adminReg,
                'type' => $type,
                'unitId' => $unitId,
            ];
            $AttendanceGroupDTO = new AttendanceGroupDTO();
            $AttendanceGroupDTO->data = $data;
            $AttendanceGroupDTO->id = $Id;
            //            $engprojectDo->userid	= $adminUserId;
            //            $engprojectDo->adminReg		= $adminReg;
            $result = $api->editAttendanceGroup($AttendanceGroupDTO);
            $pdata = [];
            if ($result->code) {
                /*****测试原型*****/
                $pdata = $result->data;
            }
            //checkstate 1是选中 0是未选中
            $data = ['msg' => '添加成功', 'code' => 200, 'data' => $pdata];
        } catch (Exception $ex) {
            $data = ['msg' => '获取失败', 'code' => 400, 'data' => []];
        }
        return json_encode($data);
    }
    //操作考勤组
    public function operationAttendanceGroup()
    {
        $do = $this->request->param('do') ? $this->request->param('do') : 0;
        ////1添加 2修改
        $Id = $this->request->param('Id') ? $this->request->param('Id') : 0;
        //考勤组Id
        $title = $this->request->param('title') ? $this->request->param('title') : 0;
        //考勤组名称
        $platformId = $this->request->param('platformId') ? $this->request->param('platformId') : 0;
        //平台ID
        $setholidaysId = $this->request->param('setholidaysId') ? $this->request->param('setholidaysId') : 0;
        //节假日设置ID
        $goDaysNum = $this->request->param('goDaysdata') ? json_decode(htmlspecialchars_decode($this->request->param('goDaysdata'))) : [];
        //一天内上下班的次数
        $unusualStatus = $this->request->param('unusualStatus') ? json_decode(htmlspecialchars_decode($this->request->param('unusualStatus'))) : [];
        //异常定义
        $coordinate = $this->request->param('coordinate') ? json_decode(htmlspecialchars_decode($this->request->param('coordinate'))) : [];
        //签到点坐标
        $coordinateName = $this->request->param('coordinateName') ? json_decode(htmlspecialchars_decode($this->request->param('coordinateName'))) : [];
        //签到地点名
        $coordinateTitle = $this->request->param('coordinateTitle') ? json_decode(htmlspecialchars_decode($this->request->param('coordinateTitle'))) : [];
        //签到地点名
        $coordinateDeviation = $this->request->param('coordinateDeviation') ? json_decode(htmlspecialchars_decode($this->request->param('coordinateDeviation'))) : [];
        //签到范围
        $groupMustUser = $this->request->param('groupMustUser') ? json_decode(htmlspecialchars_decode($this->request->param('groupMustUser'))) : [];
        //参与考勤人员
        $groupNotUser = $this->request->param('groupNotUser') ? json_decode(htmlspecialchars_decode($this->request->param('groupNotUser'))) : [];
        //无需考勤人员
        $approvalProcessOne = $this->request->param('approvalProcessOne') ? $this->request->param('approvalProcessOne') : 0;
        //请假审批流程方案ID
        $approvalProcessTwo = $this->request->param('approvalProcessTwo') ? $this->request->param('approvalProcessTwo') : 0;
        //外出审批流程方案ID
        $approvalProcessThree = $this->request->param('approvalProcessThree') ? $this->request->param('approvalProcessThree') : 0;
        //补卡审批流程方案ID
        $offDutyOut = $this->request->param('offDutyOut') ? $this->request->param('offDutyOut') : 1;
        // 下班是否需要打卡 1打卡 2不打卡
        $faceStatus = $this->request->param('faceStatus') ? $this->request->param('faceStatus') : 1;
        // 是否开启人脸 1开启 2不开启
        $trackLocation = $this->request->param('trackLocation') ? $this->request->param('trackLocation') : 1;
        // 1不开启轨迹定位 2开启轨迹定位
        $adminUserId = $this->request->param('adminUserId') ? $this->request->param('adminUserId') : 0;
        $type = $this->request->param('type') ? $this->request->param('type') : 1;
        //1正常考勤组 2公共考勤组
        $adminReg = $this->request->param('adminReg') ? getStr($this->request->param('adminReg')) : '';
        $unitId = $this->request->param('unitId') ? getStr($this->request->param('unitId')) : '';
        //        if (empty($title) || empty($setholidaysId)|| empty($platformId) || empty($goDaysNum) || empty($groupMustUser)|| empty($groupNotUser)){
        //            $data = ['msg'=>'参数错误','code'=>400,'data'=>[]];
        //            return json_encode($data);
        //        }
        if (empty($title)) {
            $data = ['msg' => '请填写考勤组名称', 'code' => 400, 'data' => []];
            return json_encode($data);
        } elseif (empty($setholidaysId)) {
            $data = ['msg' => '请选择节假日设置', 'code' => 400, 'data' => []];
            return json_encode($data);
        } elseif (empty($goDaysNum)) {
            $data = ['msg' => '请选择上班时间段', 'code' => 400, 'data' => []];
            return json_encode($data);
        } elseif (empty($coordinate)) {
            $data = ['msg' => '请选择考勤地点', 'code' => 400, 'data' => []];
            return json_encode($data);
        }
        if (empty($Id)) {
            $data = ['msg' => '参数错误', 'code' => 400, 'data' => []];
            return json_encode($data);
        }
        $lngs = array_column($coordinate,'lng');
        $lats = array_column($coordinate,'lat');

        try {
            \ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlCloudSdk'));
            $api = new AttAdminAttendanceGroupServiceClient(NULL);
            \ApiClient::build($api);
            $data = [
                'title' => $title,
                'setholidaysId' => $setholidaysId,
                'platformId' => $platformId,
                'goDaysNum' => json_encode($goDaysNum),
                'unusualStatus' => json_encode($unusualStatus),
                'coordinate' => json_encode($coordinate),
                'coordinateName' => json_encode($coordinateName),
                'coordinateTitle' => json_encode($coordinateTitle),
                'coordinateDeviation' => json_encode($coordinateDeviation),
                'groupMustUser' => json_encode($groupMustUser),
                //['units'=>[1,2,3],'userid'=>[3,5,6]]
                'groupNotUser' => json_encode($groupNotUser),
                //['units'=>[1,2,3],'userid'=>[3,5,6]]
                'approvalProcessOne' => $approvalProcessOne,
                'approvalProcessTwo' => $approvalProcessTwo,
                'approvalProcessThree' => $approvalProcessThree,
                'offDutyOut' => $offDutyOut,
                'faceStatus' => $faceStatus,
                'trackLocation' => $trackLocation,
                'adminUserId' => $adminUserId,
                'adminReg' => $adminReg,
                'type' => $type,
                'unitId' => $unitId,
            ];
            $AttendanceGroupDTO = new AttendanceGroupDTO();
            $AttendanceGroupDTO->data = $data;
            if ($do == 1) {
                //1添加 2修改
                $result = $api->addAttendanceGroup($AttendanceGroupDTO);
            } else {
                $AttendanceGroupDTO->id = $Id;
                $result = $api->editAttendanceGroup($AttendanceGroupDTO);
            }
            if ($result->code==200) {
                /*****测试原型*****/
                $pdata = $result->data;
                //checkstate 1是选中 0是未选中
                $data = ['msg' => $result->message, 'code' => $result->code, 'data' => $pdata];
            }else{
                $data = ['msg' => $result->message, 'code' => $result->code, 'data' => []];
            }

        } catch (Exception $ex) {
            $data = ['msg' => '获取失败', 'code' => 400, 'data' => []];
        }
        return json_encode($data);
    }
    //考勤组列表
    public function getAttendanceGroupList()
    {
        $id = $this->request->param('id') ? $this->request->param('id') : 0;
        //考勤组ID
        $platformId = $this->request->param('platformId') ? $this->request->param('platformId') : 0;
        //平台ID
        $unitId = $this->request->param('unitId') ? $this->request->param('unitId/d') : 0;
        //部门id  现在是用户传 改完后直接查询管理员部门完成
        $offset = $this->request->param('offset') ? $this->request->param('offset/d') : 1;
        $num = $this->request->param('num') ? $this->request->param('num/d') : 10;
        $title = $this->request->param('title') ? $this->request->param('title') : '';
        //title 考勤组名
        $departmenName = $this->request->param('departmenName') ? $this->request->param('departmenName') : '';
        //departmenName
        $unitName = $this->request->param('unitName') ? $this->request->param('unitName') : '';
        //unitName
        $status = $this->request->param('status') ? $this->request->param('status') : 0;
        //  1只返回考勤组名称 2只返回单位名称 3只返回组织名称列表
        $adminUserId = $this->request->param('adminUserId') ? $this->request->param('adminUserId') : 0;
        $adminReg = $this->request->param('adminReg') ? getStr($this->request->param('adminReg')) : '';
        if (empty($platformId)) {
            $data = ['msg' => '平台ID未传递', 'code' => 400, 'data' => []];
            return json_encode($data);
        }elseif (empty($adminUserId)) {
            $data = ['msg' => '管理员ID未传递', 'code' => 400, 'data' => []];
            return json_encode($data);
        } elseif (empty($adminReg)) {
            $data = ['msg' => 'reg未传递', 'code' => 400, 'data' => []];
            return json_encode($data);
        }

        try {
            \ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlCloudSdk'));
            $api = new AttAdminAttendanceGroupServiceClient(NULL);
            \ApiClient::build($api);
            $plaform = [];
            $data = ['adminReg' => $adminReg, 'adminUserId' => $adminUserId, 'unitId' => $unitId, 'type' => 1, 'status' => $status, 'platformId' => $platformId, 'title' => $title, 'departmenName' => $departmenName, 'unitName' => $unitName, 'id' => $id];
            $AttendanceGroupDTO = new AttendanceGroupDTO();
            $AttendanceGroupDTO->data = $data;
            $AttendanceGroupDTO->offset = $offset;
            $AttendanceGroupDTO->num = $num;
            $result = $api->getAdminAttendanceGroupList($AttendanceGroupDTO);
            if ($result->code) {
                $plaform = $result->data;
                if ($status == 0) {
                    foreach ($plaform as &$value) {
                        if ($value['goDaysNum']) {
                            $value['goDaysNum'] = unserialize($value['goDaysNum']);
                        }
                        if ($value['unusualStatus']) {
                            $value['unusualStatus'] = unserialize($value['unusualStatus']);
                        }
                        if ($value['coordinate']) {
                            $value['coordinate'] = unserialize($value['coordinate']);
                        }
                        $value['groupMustUser'] = unserialize($value['groupMustUser']);
                        $value['groupNotUser'] = unserialize($value['groupNotUser']);
                    }
                }
            }
            $data = ['msg' => '获取成功', 'code' => 200, 'data' => $plaform, 'count' => $result->counts ? $result->counts : 0];
        } catch (Exception $ex) {
            $data = ['msg' => '获取失败', 'code' => 400, 'data' => [], 'count' => 0];
        }
        return json_encode($data);
    }
    /**
     * 删除考勤组
     * @return string
     */
    public function deleteAttendanceGroup()
    {
        $id = $this->request->param('id') ? $this->request->param('id') : 0;
        if (empty($id)) {
            $data = ['msg' => '参数错误', 'code' => 400, 'data' => []];
            return json_encode($data);
        }
        try {
            \ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlCloudSdk'));
            $api = new AttAdminAttendanceGroupServiceClient(NULL);
            \ApiClient::build($api);
            $AttendanceGroupDTO = new AttendanceGroupDTO();
            $AttendanceGroupDTO->id = $id;
            $result = $api->deleteAttendanceGroup($AttendanceGroupDTO);
            $pdata = [];
            if ($result->code) {
                $pdata = $result->data;
            }
            $data = ['msg' => $result->message, 'code' => 200, 'data' => $pdata];
        } catch (Exception $ex) {
            $data = ['msg' => '删除失败', 'code' => 400, 'data' => []];
        }
        return json_encode($data);
    }
    #节假日API start#
    //获取节假日方案列表
    public function getSetholidaysList()
    {
        $setholidaysId = $this->request->param('setholidaysId') ? $this->request->param('setholidaysId') : 0;
        $platformId = $this->request->param('platformId') ? $this->request->param('platformId') : 0;
        //平台ID和考勤组ID不同时存在
        $agId = $this->request->param('agId') ? $this->request->param('agId') : 0;
        //考勤组ID
        $adminUserId = $this->request->param('adminUserId') ? $this->request->param('adminUserId') : 0;
        $adminReg = $this->request->param('adminReg') ? getStr($this->request->param('adminReg')) : '';
        if (empty($platformId) || empty($adminUserId)) {
            $data = ['msg' => '参数错误', 'code' => 400, 'data' => []];
            return json_encode($data);
        }
        try {
            \ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlCloudSdk'));
            $api = new SetholidaysServiceClient(NULL);
            \ApiClient::build($api);
            $data = ['adminReg' => $adminReg, 'agId' => $agId, 'adminUserId' => $adminUserId];
            $engprojectDo = new setholidaysDTO();
            $engprojectDo->data = $data;
            $engprojectDo->id = $setholidaysId;
            $engprojectDo->platformId = $platformId;
            $result = $api->getSetholidaysList($engprojectDo);
            $plaform = [];
            if ($result->code) {
                /*****测试原型*****/
                $plaform = $result->data;
                foreach ($plaform as &$value) {
                    $workday = unserialize($value['workday']);
                    $value['workday'] = $workday;
                    $value['specialWorkday'] = unserialize($value['specialWorkday']);
                    $value['holiday'] = unserialize($value['holiday']);
                }
            }
            //checkstate 1是选中 0是未选中
            $data = ['msg' => '获取成功', 'code' => 200, 'data' => $plaform];
        } catch (Exception $ex) {
            $data = ['msg' => '获取失败', 'code' => 400, 'data' => []];
        }
        return json_encode($data);
    }
    //添加节假日方案
    public function addSetholidays()
    {
        $name = $this->request->param('name') ? $this->request->param('name') : 0;
        $work = $this->request->param('work') ? explode(',', $this->request->param('work')) : [];
        //工作日定义
        //['2018-07-11@?(春节补)']
        $special = $this->request->param('special/a') ? $this->request->param('special/a') : [];
        //特殊工作日定义
        $holiday = $this->request->param('holiday/a') ? $this->request->param('holiday/a') : [];
        //节假日定义
        $adminUserId = $this->request->param('adminUserId') ? $this->request->param('adminUserId') : 0;
        $platformId = $this->request->param('platformId') ? $this->request->param('platformId') : 0;
        $adminReg = $this->request->param('adminReg') ? getStr($this->request->param('adminReg')) : '';
        if (empty($platformId) || empty($adminUserId)) {
            $data = ['msg' => '参数错误', 'code' => 400, 'data' => []];
            return json_encode($data);
        }
        try {
            \ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlCloudSdk'));
            $api = new SetholidaysServiceClient(NULL);
            \ApiClient::build($api);
            $data = [
                'name' => $name,
                'workday' => serialize($work),
                //工作日定义 ['1','2','3','4','5','6','7']
                'platformId' => $platformId,
                'adminUserId' => $adminUserId,
                'specialWorkday' => serialize($special),
                //特殊工作日定义 [2018-02-11(春节(补))','2018-02-11(清明节(补))','2018-02-11(春节(补))']
                'holiday' => serialize($holiday),
            ];
            $engprojectDo = new setholidaysDTO();
            $engprojectDo->data = $data;
            $engprojectDo->platformId = $platformId;
            $result = $api->addSetholidays($engprojectDo);
            $plaform = [];
            if ($result->code) {
                /*****测试原型*****/
                $plaform = $result->data[0];
            }
            $data = ['msg' => $result->message, 'code' => 200, 'data' => $plaform];
        } catch (Exception $ex) {
            $data = ['msg' => '添加失败', 'code' => 400, 'data' => []];
        }
        return json_encode($data);
    }
    //修改节假日方案
    public function editSetholidays()
    {
        $id = $this->request->param('id') ? $this->request->param('id') : 0;
        //节假日ID
        $name = $this->request->param('name') ? $this->request->param('name') : 0;
        $work = $this->request->param('work/a') ? explode(',', $this->request->param('work')) : [];
        //工作日定义
        //['2018-07-11@?(春节补)']
        $special = $this->request->param('special/a') ? $this->request->param('special/a') : [];
        //特殊工作日定义
        $holiday = $this->request->param('holiday/a') ? $this->request->param('holiday/a') : [];
        //节假日定义
        $adminUserId = $this->request->param('adminUserId') ? $this->request->param('adminUserId') : 0;
        $platformId = $this->request->param('platformId') ? $this->request->param('platformId') : 0;
        $adminReg = $this->request->param('adminReg') ? getStr($this->request->param('adminReg')) : '';
        if (empty($platformId) || empty($adminUserId)) {
            $data = ['msg' => '参数错误', 'code' => 400, 'data' => []];
            return json_encode($data);
        }
        try {
            \ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlCloudSdk'));
            $api = new SetholidaysServiceClient(NULL);
            \ApiClient::build($api);
            $data = [
                'name' => $name,
                'workday' => serialize($work),
                //工作日定义 ['1','2','3','4','5','6','7']
                'platformId' => $platformId,
                'adminUserId' => $adminUserId,
                'specialWorkday' => serialize($special),
                //特殊工作日定义 [2018-02-11(春节(补))','2018-02-11(清明节(补))','2018-02-11(春节(补))']
                'holiday' => serialize($holiday),
            ];
            $engprojectDo = new setholidaysDTO();
            $engprojectDo->data = $data;
            $engprojectDo->id = $id;
            $engprojectDo->platformId = $platformId;
            $result = $api->editSetholidays($engprojectDo);
            $plaform = [];
            if ($result->code) {
                /*****测试原型*****/
                $plaform = $result->data[0];
            }
            $data = ['msg' => $result->message, 'code' => 200, 'data' => $plaform];
        } catch (Exception $ex) {
            $data = ['msg' => '添加失败', 'code' => 400, 'data' => []];
        }
        return json_encode($data);
    }
    //操作节假日方案
    public function operationSetholidays()
    {
        $id = $this->request->param('id') ? $this->request->param('id') : 0;
        //节假日ID
        $do = $this->request->param('do') ? $this->request->param('do') : 0;
        //1添加 2删除
        $name = $this->request->param('name') ? $this->request->param('name') : 0;
        $work = $this->request->param('work') ? explode(',', $this->request->param('work')) : [];
        //工作日定义
        //['2018-07-11@?(春节补)']
        $special = $this->request->param('special') ? json_decode(htmlspecialchars_decode($this->request->param('special'))) : [];
        //特殊工作日定义
        $holiday = $this->request->param('holiday') ? json_decode(htmlspecialchars_decode($this->request->param('holiday'))) : [];
        //节假日定义
        $adminUserId = $this->request->param('adminUserId') ? $this->request->param('adminUserId') : 0;
        $platformId = $this->request->param('platformId') ? $this->request->param('platformId') : 0;
        $adminReg = $this->request->param('adminReg') ? getStr($this->request->param('adminReg')) : '';
        if (empty($platformId) || empty($adminUserId) || empty($do) || empty($name) || empty($work)) {
            $data = ['msg' => '参数错误', 'code' => 400, 'data' => []];
            return json_encode($data);
        }
        try {
            \ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlCloudSdk'));
            $api = new SetholidaysServiceClient(NULL);
            \ApiClient::build($api);
            $data = [
                'do' => $do,
                'name' => $name,
                'workday' => serialize($work),
                //工作日定义 ['1','2','3','4','5','6','7']
                'platformId' => $platformId,
                'adminUserId' => $adminUserId,
                'specialWorkday' => serialize($special),
                //特殊工作日定义 [2018-02-11(春节(补))','2018-02-11(清明节(补))','2018-02-11(春节(补))']
                'holiday' => serialize($holiday),
            ];
            $engprojectDo = new setholidaysDTO();
            $engprojectDo->data = $data;
            $engprojectDo->id = $id;
            $engprojectDo->platformId = $platformId;
            $result = $api->operationSetholidays($engprojectDo);
            $plaform = [];
            if ($result->code) {
                /*****测试原型*****/
                $plaform = $result->data[0];
            }
            $data = ['msg' => $result->message, 'code' => 200, 'data' => $plaform];
        } catch (Exception $ex) {
            $data = ['msg' => '添加失败', 'code' => 400, 'data' => []];
        }
        return json_encode($data);
    }
    /**
     * 删除节假日方案
     * @return string
     */
    public function deleteSetholidays()
    {
        $id = $this->request->param('id') ? $this->request->param('id') : 0;
        if (empty($id)) {
            $data = ['msg' => '参数错误', 'code' => 400, 'data' => []];
            return json_encode($data);
        }
        try {
            \ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlCloudSdk'));
            $api = new SetholidaysServiceClient(NULL);
            \ApiClient::build($api);
            $engprojectDo = new setholidaysDTO();
            $engprojectDo->id = $id;
            $result = $api->deleteSetholidays($engprojectDo);
            $pdata = [];
            if ($result->code) {
                $pdata = $result->data;
            }
            $data = ['msg' => $result->message, 'code' => 200, 'data' => $pdata];
        } catch (Exception $ex) {
            $data = ['msg' => '删除失败', 'code' => 400, 'data' => []];
        }
        return json_encode($data);
    }
    #节假日API  end#
    #审批流程 start#
    /**
     * 审批流程列表 或者 单个审批流程
     * @return string
     */
    public function getApprovalProcessList()
    {
        $type = $this->request->param('type') ? $this->request->param('type') : 0;
        //1请假流程 2外出流程 3补卡流程
        $status = $this->request->param('status') ? $this->request->param('status') : 0;
        //1默认流程 2特定流程 3特殊人群流程
        $adminUserId = $this->request->param('adminUserId') ? $this->request->param('adminUserId') : 0;
        $platformId = $this->request->param('platformId') ? $this->request->param('platformId') : 0;
        $id = $this->request->param('id') ? $this->request->param('id') : 0;
        $agId = $this->request->param('agId') ? $this->request->param('agId') : 0;
        $unitid = $this->request->param('unitid') ? $this->request->param('unitid') : 0;
        $unitids = $this->request->param('unitids') ? $this->request->param('unitids') : '';
        //[1,2,3]
        $adminReg = $this->request->param('adminReg') ? getStr($this->request->param('adminReg')) : '';
        $agName = $this->request->param('agName') ? getStr($this->request->param('agName')) : '';
        $realName = $this->request->param('realName') ? getStr($this->request->param('realName')) : '';
        //考勤组名称
        if (empty($platformId) || empty($adminUserId) || empty($status)) {
            $data = ['msg' => '参数错误', 'code' => 400, 'data' => []];
            return json_encode($data);
        }
        if (!empty($unitids)){
            $unitids = explode(',',$unitids);
            $tn = count($unitids);
            $unitids = $unitids[$tn-1];
        }
        try {
            \ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlCloudSdk'));
            $api = new ApprovalProcessServiceClient(NULL);
            $apiUser = new AttAdminUserServiceClient(NULL);
            \ApiClient::build($api);
            \ApiClient::build($apiUser);
            $approvalProcessDTO = new approvalProcessDTO();
            $approvalProcessDTO->id = $id;
            $approvalProcessDTO->type = $type;
            $approvalProcessDTO->status = $status;
            $approvalProcessDTO->name = $agName;
            //考勤组名称
            $approvalProcessDTO->platformId = $platformId;
            $approvalProcessDTO->data = ['adminUserId' => $adminUserId, 'adminReg' => $adminReg, 'realName' => $realName, 'agId' => $agId, 'unitids' => $unitids];
            $result = $api->getApprovalProcessList($approvalProcessDTO);
            $pdata = [];
            if ($result->code) {
                $plaform = $result->data;
                $member = [];
                $userinfos = [];
                $levels = array("", "一", "二", "三", "四", "五", "七", "八", "九", "十");
                //先定义一个数组
                if ($plaform[0]){
                    foreach ($plaform as $key => $value) {
                        $pdata[$key]['id'] = $value['id'];
                        $pdata[$key]['name'] = $value['name'];
                        if (isset($value['type'])) {
                            $pdata[$key]['type'] = $value['type'];
                        }
                        if (isset($value['agName'])) {
                            $pdata[$key]['agName'] = $value['agName'];
                        }
                        if (isset($value['organizationName'])) {
                            $pdata[$key]['organizationName'] = $value['organizationName'];
                        }
                        if (isset($value['memberId'])) {
                            $pdata[$key]['memberId'] = $value['memberId'];
                        }
                        if (isset($value['realName'])) {
                            $pdata[$key]['realName'] = $value['realName'];
                        }
                        if (isset($value['unitName'])) {
                            $pdata[$key]['unitName'] = $value['unitName'];
                        }
                        if (isset($value['memberId']) && $status==3 && $id) {
                            $pdata[$key]['memberId'] = unserialize($value['memberId']);
                        }
                        if (isset($value['rules'])) {
                            $pdata[$key]['rules'] = unserialize($value['rules']);
                            foreach ($pdata[$key]['rules'] as &$vv) {
                                if ($vv['type'] == 'target_member') {
                                    $member[$vv['target_member']] = str_replace('manager', '', $vv['target_member']);
                                } else {
                                    $vv['name'] = "第".$vv['level'] . "级主管";
//                                    if ($vv['level']==1){
//                                        $vv['name'] = "直接主管";
//                                    }else{
//                                        $vv['name'] = $levels[$vv['level']] . "级主管";
//                                    }
                                }
                            }

                            //根据用户ID 查询用户信息
                            if (!empty($member)) {
                                $UserDTO = new UserDTO();
                                $member = implode(',', $member);
                                $UserDTO->where = " id IN({$member}) and status =2 ";
                                $UserDTO->data = ['likeName'=>"", 'departmentId'=>"", 'userId'=>"$member", 'unitId'=>$unitid, 'positionId'=>"",'platformId'=>$platformId,'adminUserId'=>$adminUserId,'type'=>$type,'photoStatus'=>""];
                                $userinfo = $apiUser->getMemberList($UserDTO);

                                if ($userinfo->code) {
                                    $userinfo = $userinfo->data;
                                    foreach ($userinfo as $userkey => $userValue) {
                                        foreach ($pdata[$key]['rules'] as &$vv) {
                                            if ($vv['type'] == 'target_member' && $vv['target_member'] == "manager" . $userValue['id']) {
                                                $vv['name'] = $userValue['realName'];
                                            }
                                        }
                                        $userinfos["manager" . $userValue['id']]['id'] = $userValue['id'];
                                        $userinfos["manager" . $userValue['id']]['userName'] = $userValue['userName'];
                                        $userinfos["manager" . $userValue['id']]['userName'] = $userValue['userName'];
                                        $userinfos["manager" . $userValue['id']]['realName'] = $userValue['realName'];
                                    }
                                }
                            }
                            $pdata[$key]['userDetail'] = $userinfos;
                        }
                    }
                }

            }
            $data = ['msg' => $result->message, 'code' => 200, 'data' => $pdata, 'count' => !empty($result->counts) ? $result->counts : 0];
        } catch (Exception $ex) {
            $data = ['msg' => '添加失败', 'code' => 400, 'data' => [], 'count' => 0];
        }
        return json_encode($data);
    }
    /**
     * 操作审批流程
     * @return string
     */
    public function operationApprovalProcess()
    {
        $id = $this->request->param('id') ? $this->request->param('id') : 0;
        //
        $name = $this->request->param('name') ? $this->request->param('name') : 0;
        //
        $type = $this->request->param('type') ? $this->request->param('type') : 0;
        //1请假流程 2外出流程 3补卡流程
        $status = $this->request->param('status') ? $this->request->param('status') : 1;
        //1默认流程 2特定流程 3特殊人群流程
        $adminUserId = $this->request->param('adminUserId') ? $this->request->param('adminUserId') : 0;
        $memberIds = $this->request->param('memberIds') ? $this->request->param('memberIds') : 0;
        //逗号分割的人员ID
        $platformId = $this->request->param('platformId') ? $this->request->param('platformId') : 0;
        $rules = $this->request->param('rules') ? object_to_array(json_decode(htmlspecialchars_decode($this->request->param('rules')))) : [];
        //rules   [['type'=>'target_management','level'=>1],['type'=>'target_member','target_member'=>'manager3']]
        $unitid = $this->request->param('unitid') ? $this->request->param('unitid') : 0;
        $adminReg = $this->request->param('adminReg') ? getStr($this->request->param('adminReg')) : '';
        $do = $this->request->param('do') ? getStr($this->request->param('do')) : 0;
        //1添加 2删除
        if (empty($platformId) || empty($adminUserId) || empty($type) || empty($rules) || empty($do)) {
            $data = ['msg' => '参数错误', 'code' => 400, 'data' => []];
            return json_encode($data);
        }
        //查找规则中是否存在 相同审批主管
        $management = [];
        foreach ($rules as $m) {
            if ($m['type'] == 'target_management') {
                $management[] = $m;
            }
        }
        $managementLevel = array_column($management, 'level');
        if (count($managementLevel) != count(array_unique($managementLevel))) {
            $data = ['msg' => '该规则中存在重复主管,请删除后保存！', 'code' => 400, 'data' => []];
            return json_encode($data);
        }
        try {
            \ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlCloudSdk'));
            $api = new ApprovalProcessServiceClient(NULL);
            \ApiClient::build($api);
            $approvalProcessDTO = new approvalProcessDTO();
            $approvalProcessDTO->data = ['type' => $type, 'id' => $id, 'do' => $do, 'status' => $status, 'memberIds' => $memberIds, 'name' => $name, 'adminUserId' => $adminUserId, 'platformId' => $platformId, 'createTime' => time(), 'rules' => serialize($rules)];
            $result = $api->operationApprovalProcess($approvalProcessDTO);
            $pdata = [];
            if ($result->code) {
                $pdata = $result->data;
            }
            $data = ['msg' => $result->message, 'code' => 200, 'data' => $pdata];
        } catch (Exception $ex) {
            $data = ['msg' => '添加失败', 'code' => 400, 'data' => []];
        }
        return json_encode($data);
    }
    /**
     * 编辑审批流程
     * @return string
     */
    public function editApprovalProcess()
    {
        $id = $this->request->param('id') ? $this->request->param('id') : 0;
        //流程ID
        $name = $this->request->param('name') ? $this->request->param('name') : 0;
        //1请假流程 2外出流程 3补卡流程
        $type = $this->request->param('type') ? $this->request->param('type') : 0;
        //1请假流程 2外出流程 3补卡流程
        $status = $this->request->param('status') ? $this->request->param('status') : 1;
        //1默认流程 2特定流程 3特殊人群流程
        $adminUserId = $this->request->param('adminUserId') ? $this->request->param('adminUserId') : 0;
        $memberId = $this->request->param('memberId') ? $this->request->param('memberId') : 0;
        $platformId = $this->request->param('platformId') ? $this->request->param('platformId') : 0;
        $rules = $this->request->param('rules/a') ? $this->request->param('rules/a') : [];
        //rules   [['type'=>'target_management','level'=>1],['type'=>'target_member','target_member'=>'manager3']]
        $unitid = $this->request->param('unitid') ? $this->request->param('unitid') : 0;
        $adminReg = $this->request->param('adminReg') ? getStr($this->request->param('adminReg')) : '';
        if (empty($platformId) || empty($adminUserId) || empty($name) || empty($type) || empty($rules)) {
            $data = ['msg' => '参数错误', 'code' => 400, 'data' => []];
            return json_encode($data);
        }
        try {
            \ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlCloudSdk'));
            $api = new ApprovalProcessServiceClient(NULL);
            \ApiClient::build($api);
            $approvalProcessDTO = new approvalProcessDTO();
            $approvalProcessDTO->id = $id;
            $approvalProcessDTO->data = ['type' => $type, 'status' => $status, 'name' => $name, 'unitid' => $unitid, 'memberId' => $memberId, 'adminUserId' => $adminUserId, 'platformId' => $platformId, 'createTime' => time(), 'rules' => serialize($rules)];
            $result = $api->editApprovalProcess($approvalProcessDTO);
            $pdata = [];
            if ($result->code) {
                $pdata = $result->data;
            }
            $data = ['msg' => $result->message, 'code' => 200, 'data' => $pdata];
        } catch (Exception $ex) {
            $data = ['msg' => '添加失败', 'code' => 400, 'data' => []];
        }
        return json_encode($data);
    }
    /**
     * 删除审批流程
     * @return string
     */
    public function deleteApprovalProcess()
    {
        $id = $this->request->param('id') ? $this->request->param('id') : 0;
        $userId = $this->request->param('userId') ? $this->request->param('userId') : 0;
        if (empty($id)) {
            $data = ['msg' => '参数错误', 'code' => 400, 'data' => []];
            return json_encode($data);
        }
        try {
            \ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlCloudSdk'));
            $api = new ApprovalProcessServiceClient(NULL);
            \ApiClient::build($api);
            $approvalProcessDTO = new approvalProcessDTO();
            $approvalProcessDTO->id = $id;
            $approvalProcessDTO->data = ['userId' => $userId];
            $result = $api->deleteApprovalProcess($approvalProcessDTO);
            $pdata = [];
            if ($result->code) {
                $pdata = $result->data;
            }
            $data = ['msg' => $result->message, 'code' => 200, 'data' => $pdata];
        } catch (Exception $ex) {
            $data = ['msg' => '删除失败', 'code' => 400, 'data' => []];
        }
        return json_encode($data);
    }
    /**
     * 审批流程 启用及其停用
     * @return string
     */
    public function stopApprovalProcess()
    {
        $id = $this->request->param('id') ? $this->request->param('id') : 0;
        $stop = $this->request->param('stop') ? $this->request->param('stop') : 0;
        //1启用 2停用
        $status = $this->request->param('status') ? $this->request->param('status') : 0;
        //1默认流程 2特定流程 3特殊人群流程
        $type = $this->request->param('type') ? $this->request->param('type') : 0;
        //1请假流程 2外出流程 3补卡流程
        $platformId = $this->request->param('platformId') ? $this->request->param('platformId') : 0;
        //1默认流程 2特定流程 3特殊人群流程
        if (empty($stop) || $status != 1) {
            $data = ['msg' => '参数错误', 'code' => 400, 'data' => []];
            return json_encode($data);
        }
        try {
            \ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlCloudSdk'));
            $api = new ApprovalProcessServiceClient(NULL);
            \ApiClient::build($api);
            $approvalProcessDTO = new approvalProcessDTO();
            $approvalProcessDTO->id = $id;
            $approvalProcessDTO->stop = $stop;
            $approvalProcessDTO->type = $type;
            $approvalProcessDTO->status = $status;
            $approvalProcessDTO->platformId = $platformId;
            $result = $api->stopApprovalProcess($approvalProcessDTO);
            $pdata = [];
            if ($result->code) {
                $pdata = $result->data;
            }
            $data = ['msg' => $result->message, 'code' => 200, 'data' => $pdata];
        } catch (Exception $ex) {
            $data = ['msg' => '添加失败', 'code' => 400, 'data' => []];
        }
        return json_encode($data);
    }
    #审批流程 end#
    #组织架构 start#
    /**
     * 人员组织架构列表
     * @return string
     */
    public function getUnitsMemberRelationList()
    {
        $adminUserId = $this->request->param('adminUserId') ? $this->request->param('adminUserId') : 0;
        $platformId = $this->request->param('platformId') ? $this->request->param('platformId') : 0;
        $unitId = $this->request->param('unitId') ? $this->request->param('unitId') : 0;
        $adminReg = $this->request->param('adminReg') ? getStr($this->request->param('adminReg')) : '';
        $type = $this->request->param('type') ? getStr($this->request->param('type')) : 1;
        //1带树形结构 2列表
        if (empty($platformId) || empty($adminUserId)) {
            $data = ['msg' => '参数错误', 'code' => 400, 'data' => []];
            return json_encode($data);
        }
        try {
            \ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlCloudSdk'));
            $api = new AttAdminUserServiceClient(NULL);
            \ApiClient::build($api);
            $engprojectDo = new UserDTO();
            $engprojectDo->platformId = $platformId;
            $engprojectDo->unitId = $unitId;
            $engprojectDo->data = ['adminUserId' => $adminUserId, 'type' => $type];
            $result = $api->getUnitsMemberRelationList($engprojectDo);
            $plaform = [];
            if ($result->code) {
                $plaform = json_decode($result->data[0][0]);
            }
            $data = ['msg' => $result->message, 'code' => 200, 'data' => $plaform];
        } catch (Exception $ex) {
            $data = ['msg' => '添加失败', 'code' => 400, 'data' => []];
        }
        return json_encode($data);
    }
    #组织架构 end#
    public function getPlatformManagementLevel()
    {
        $adminUserId = $this->request->param('adminUserId') ? $this->request->param('adminUserId') : 0;
        $platformId = $this->request->param('platformId') ? $this->request->param('platformId') : 0;
        $unitId = $this->request->param('unitId') ? $this->request->param('unitId') : 0;
        $adminReg = $this->request->param('adminReg') ? getStr($this->request->param('adminReg')) : '';
        if (empty($platformId) || empty($adminUserId)) {
            $data = ['msg' => '参数错误', 'code' => 400, 'data' => []];
            return json_encode($data);
        }
        try {
            \ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlCloudSdk'));
            $api = new AttAdminAttendanceGroupServiceClient(NULL);
            \ApiClient::build($api);
            $AttendanceGroupDTO = new AttendanceGroupDTO();
            $AttendanceGroupDTO->data = ['platformId' => $platformId, 'unitId' => $unitId];
            $result = $api->getPlatformManagementLevel($AttendanceGroupDTO);
            $plaform = [];
            if ($result->code) {
                $plaform = $result->data;
            }
            $data = ['msg' => $result->message, 'code' => 200, 'data' => $plaform];
        } catch (Exception $ex) {
            $data = ['msg' => '添加失败', 'code' => 400, 'data' => []];
        }
        return json_encode($data);
    }
}